<template>
  <el-select v-model="selectValue" :placeholder="placeholder" :size="size" @change="onChange">
    <el-option v-for="(item,key,index) in datas" :key="index" :label="item.label" :value="item.value"/>
  </el-select>
</template>
<script>

export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    placeholder: {
      type: String,
      default: ''
    },
    size: {
      type: String,
      default: 'medium'
    }
  },
  data() {
    return {
      datas: [
        {label:'宝马',value:1},
        {label:'奔驰',value:3},
        {label:'奥迪',value:4}
      ],
      selectValue: ''

    }
  },
  watch: {
    value: function(v) {
      this.selectValue = v
    }
  },
  mounted() {
    debugger
    this.value = this.value || ''
    getCarTypes().then(res => {
      this.datas = res.map(v => {
        debugger
        return {
          label: v.typeName,
          value: v.typeId
        }
      }, this)
      this.datas.unshift({ label: '请选择车型', value: '' })
    })
  },
  methods: {
    onChange(v) {
      this.$emit('update:value', v)
    }
  }
}
</script>

<style scoped>

</style>
